<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户id" prop="yhshId">
        <el-input
          v-model="queryParams.yhshId"
          placeholder="请输入用户id，主键"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户昵称" prop="yhshName">
        <el-input
          v-model="queryParams.yhshName"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="yhshPhone">
        <el-input
          v-model="queryParams.yhshPhone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核类型" prop="yhshlxId">
<!--        <el-input-->
<!--          v-model="queryParams.yhshlxId"-->
<!--          placeholder="请输入用户审核类型id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
        <el-select v-model="queryParams.yhshlxId"
                   placeholder="请选择下拉选择"
                   clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in shenheOptions"
                     :key="index"
                     :label="item.yhshlxName"
                     :value="item.yhshlxId"
                     :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="提交时间" prop="yhshTjsj">
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.yhshTjsj"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择提交时间">-->
<!--        </el-date-picker>-->
        <el-date-picker
          v-model="daterangeYhshTjsj"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="审核状态" prop="statusId">
<!--        <el-input-->
<!--          v-model="queryParams.statusId"-->
<!--          placeholder="请输入审核状态id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
        <el-select v-model="queryParams.statusId"
                   placeholder="请选择下拉选择"
                   clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in zhuangtaiOptions"
                     :key="index"
                     :label="item.statusName"
                     :value="item.statusId"
                     :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核人" prop="yhshShenheren">
        <el-input
          v-model="queryParams.yhshShenheren"
          placeholder="请输入审核人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:yonghuxinxishenhe:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:yonghuxinxishenhe:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:yonghuxinxishenhe:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:yonghuxinxishenhe:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="yonghuxinxishenheList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="流水号，自增" align="center" prop="yhshLsid" />
      <el-table-column label="用户id，主键" align="center" prop="yhshId" />
      <el-table-column label="用户昵称" align="center" prop="yhshName" />
      <el-table-column label="手机号" align="center" prop="yhshPhone" />
      <el-table-column label="审核类型" align="center" prop="yonghuxinxishenheleixing.yhshlxName" />
      <el-table-column label="新信息" align="center" prop="yhshNew" width="100">
        <template slot-scope="scope">
<!--          <image-preview :src="scope.row.yhshNew" :width="50" :height="50"/>-->
          <div v-if="scope.row.yhshlxId === 1">
            <image-preview :src="scope.row.yhshNew" :width="50" :height="50"/>
          </div>
          <div v-else-if="scope.row.yhshlxId === 2">
            {{ scope.row.yhshNew }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="旧信息" align="center" prop="yhshOld" width="100">
        <template slot-scope="scope">
<!--          <image-preview :src="scope.row.yhshOld" :width="50" :height="50"/>-->
          <div v-if="scope.row.yhshlxId === 1">
            <image-preview :src="scope.row.yhshOld" :width="50" :height="50"/>
          </div>
          <div v-else-if="scope.row.yhshlxId === 2">
            {{ scope.row.yhshOld }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="yhshTjsj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.yhshTjsj, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="shenhezhuangtai.statusName" />
      <el-table-column label="审核人" align="center" prop="yhshShenheren" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:yonghuxinxishenhe:edit']"
          >审核通过</el-button>
          <el-button icon="el-icon-edit" @click="handleUpdate1(scope.row)" type="text" size="mini">审核拒绝</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:yonghuxinxishenhe:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户信息审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id，主键" prop="yhshId">
          <el-input v-model="form.yhshId" placeholder="请输入用户id，主键" />
        </el-form-item>
        <el-form-item label="用户昵称" prop="yhshName">
          <el-input v-model="form.yhshName" placeholder="请输入用户昵称" />
        </el-form-item>
<!--        <el-form-item label="手机号" prop="yhshPhone">-->
<!--          <el-input v-model="form.yhshPhone" placeholder="请输入手机号" />-->
<!--        </el-form-item>-->
        <el-form-item label="用户审核类型id" prop="yhshlxId">
          <el-input v-model="form.yhshlxId" placeholder="请输入用户审核类型id" />
        </el-form-item>
        <el-form-item label="新信息" prop="yhshNew">
<!--          <image-upload v-model="form.yhshNew"/>-->
          <template v-if="form.yhshlxId === 1">
            <image-upload v-model="form.yhshNew"/>
          </template>
          <template v-else-if="form.yhshlxId === 2">
            <el-input v-model="form.yhshNew" placeholder="请输入用户昵称作为新信息" readonly :value="form.yhshName" />
          </template>
        </el-form-item>
        <el-form-item label="旧信息" prop="yhshOld">
<!--          <image-upload v-model="form.yhshOld"/>-->
          <template v-if="form.yhshlxId === 1">
            <image-upload v-model="form.yhshOld"/>
          </template>
          <template v-else-if="form.yhshlxId === 2">
            <el-input v-model="form.yhshOld" placeholder="请输入用户昵称作为旧信息" readonly :value="form.yhshName" />
          </template>
        </el-form-item>
<!--        <el-form-item label="提交时间" prop="yhshTjsj">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.yhshTjsj"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择提交时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
        <el-form-item label="审核状态id" prop="statusId">
          <el-input v-model="form.statusId" placeholder="请输入审核状态id" />
        </el-form-item>
<!--        <el-form-item label="审核人" prop="yhshShenheren">-->
<!--          <el-input v-model="form.yhshShenheren" placeholder="请输入审核人" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listYonghuxinxishenhe, getYonghuxinxishenhe, delYonghuxinxishenhe, addYonghuxinxishenhe, updateYonghuxinxishenhe,listShenhezhuangtai,listYonghuxinxishenheleixing } from "@/api/system/yonghuxinxishenhe";
import {updateYonghu} from '@/api/system/yonghu'
export default {
  name: "Yonghuxinxishenhe",
  data() {
    return {
      shenheOptions:[],
      zhuangtaiOptions:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息审核表格数据
      yonghuxinxishenheList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 审核人时间范围
      daterangeYhshTjsj: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        yhshId: null,
        yhshName: null,
        yhshPhone: null,
        yhshlxId: null,
        yhshNew: null,
        yhshOld: null,
        yhshTjsj: null,
        statusId: null,
        yhshShenheren: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getShenhezhuangtaiList();
    this.getYonghuxinxishenheleixingList()
  },
  methods: {
    /** 查询用户信息审核列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeYhshTjsj && '' != this.daterangeYhshTjsj) {
        this.queryParams.params["beginYhshTjsj"] = this.daterangeYhshTjsj[0];
        this.queryParams.params["endYhshTjsj"] = this.daterangeYhshTjsj[1];
      }
      listYonghuxinxishenhe(this.queryParams).then(response => {
        this.yonghuxinxishenheList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getShenhezhuangtaiList() {
      listShenhezhuangtai().then(response => {
        this.zhuangtaiOptions = response.rows;
      });
    },
    getYonghuxinxishenheleixingList() {
      listYonghuxinxishenheleixing().then(response => {
        this.shenheOptions = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        yhshLsid: null,
        yhshId: null,
        yhshName: null,
        yhshPhone: null,
        yhshlxId: null,
        yhshNew: null,
        yhshOld: null,
        yhshTjsj: null,
        statusId: null,
        yhshShenheren: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.yhshLsid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户信息审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const yhshLsid = row.yhshLsid || this.ids
      getYonghuxinxishenhe(yhshLsid).then(response => {
        this.form = response.data;
        console.log(this.form);
        this.open = true;
        this.title = "修改用户信息审核";
      });
    },
    handleUpdate1(row) {
      this.form.yhshLsid=row.yhshLsid;
      updateYonghuxinxishenhe({yhshLsid:this.form.yhshLsid,statusId:3}).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.open = false;
        this.getList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.yhshLsid != null) {
            // updateYonghuxinxishenhe(this.form).then(response => {
            //   this.$modal.msgSuccess("修改成功");
            //   this.open = false;
            //   this.getList();
            // });
            if (this.form.yhshId===1){
              updateYonghu({yhId:this.form.yhshId,yhPicture:this.form.yhshNew}).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
              updateYonghuxinxishenhe({yhshLsid:this.form.yhshLsid,statusId:2}).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }else{
              updateYonghu({yhId:this.form.yhshId,yhName:this.form.yhshNew}).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
              updateYonghuxinxishenhe({yhshLsid:this.form.yhshLsid,statusId:2}).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }
          } else {
            addYonghuxinxishenhe(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const yhshLsid = row.yhshLsid || this.ids;
      this.$modal.confirm('是否确认删除用户信息审核编号为"' + yhshLsids + '"的数据项？').then(function() {
        return delYonghuxinxishenhe(yhshLsids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/yonghuxinxishenhe/export', {
        ...this.queryParams
      }, `yonghuxinxishenhe_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
